package com.winit.config.web;

import com.winit.common.base.BaseController;
import com.winit.common.util.Constants;
import com.winit.config.manager.ResourceConfigManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.UUID;

/**
 * Created by wangjian on 2017/9/28.
 */
@RestController
@Api(value = "resource", tags = {"resource"}, description = "resource")
@RequestMapping(value = "/api/v1/resource")
public class ResourceConfigController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(ResourceConfigController.class);

    @Autowired
    ResourceConfigManager resourceConfigManager;

    @RequestMapping(value = "/get", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取resource类型配置")
    public
    @ResponseBody
    Map get(@ApiParam(value = "配置id", required = false) @RequestParam(value = "id", required = false) UUID id,
            @ApiParam(value = "应用类型,app tag", required = false) @RequestParam(value = "appTag", required = false) String appTag,
            @ApiParam(value = "环境tag", required = false) @RequestParam(value = "envTag", required = false) String envTag,
            @ApiParam(value = "区域tag", required = false) @RequestParam(value = "zoneTag", required = false) String zoneTag,
            @ApiParam(value = "资源tag", required = false) @RequestParam(value = "resourceTag", required = false) String resourceTag,
            HttpServletRequest request, HttpServletResponse response) {
        logger.info("com.winit.config.web.ResourceConfigController.get: id=" + id + ",appTag:" + appTag + ",envTag:" + envTag + ",zoneTag:" + zoneTag + ",resourceTag:" + resourceTag);
        Map map = getRtn(Constants.RTN_SUCCESS_CODE, "", resourceConfigManager.getResourceList(id, appTag,envTag, zoneTag, resourceTag));
        logger.info("com.winit.config.web.ResourceConfigController.get: id=" + id + ",appTag:" + appTag + ",envTag:" + envTag + ",zoneTag:" + zoneTag + ",resourceTag:" + resourceTag + ",map=" + map);
        return map;
    }
}
